package com.py.feign.service;

import com.py.feign.service.impl.FeignServiceHelloCircuitBreaker;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * feign的接口定义（既不是provider，也不是consumer，只是包含了一个fallback）
 * 此处的value对应provider的application.yml中spring.application.name的值
 * 这里的fallback只有调用本地服务发生异常时才会触发，若调用来自远程，即使发生error，也不会触发
 * @author bingtangli
 * @date 2025/07/09
 */
@FeignClient(value = "service-hello", fallback = FeignServiceHelloCircuitBreaker.class)
public interface FeignServiceHello {

    /**
     * 该接口对应Controller中定义的方法
     * @param name
     * @return
     */
    @RequestMapping(value = "/hello", method = RequestMethod.GET)
    String sayHelloFromClientOne(@RequestParam(value = "name") String name);

    /**
     * 即便url相同，也不必担心fallback冲突，因为fallback基于controller的方法名进行区分
     * @param name
     * @return {@link String}
     */
    @RequestMapping(value = "/hello", method = RequestMethod.GET)
    String hello(@RequestParam(value = "name") String name);
}
